package com.petadoption.serverclient.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

@Component
public class MyCodeGenerator {

    @Autowired
    private DataSource dataSource;

    public void excute() {
        FastAutoGenerator.create(new DataSourceConfig.Builder(dataSource))
                .globalConfig(builder -> builder
                        .outputDir(System.getProperty("user.dir") + "/src/main/java")
                        .author("汪仕杰")
                )
                //包参数配置
                .packageConfig(builder -> builder
                        .parent("com.petadoption.serverclient")
                        .entity("entity")
                        .service("service")
                        .serviceImpl("service.impl")
                        .mapper("mapper")
                        .xml("mapper")
                        .controller("controller")
                )
                //模板配置
//                .templateConfig(builder -> builder
//                        .entity()
//                        .service()
//                        .mapper()
//                        .xml()
//                        .controller()
//                )
                //策略配置
//                .strategyConfig(builder -> builder
//
//                )
                //注入配置
//                .injectionConfig(builder -> builder
//                        .build()
//                )
                //引擎
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }

}
